package model.load
{
	import flash.net.URLLoaderDataFormat;
	import flash.utils.ByteArray;
	
	import global.GameState;
	
	public class XmlLoadMessage extends AbsLoadMessage
	{
		private var backFunction:Function;
		
		
		public function XmlLoadMessage(backFunction:Function)
		{
			this.backFunction = backFunction;
			//_dataFormat = URLLoaderDataFormat.TEXT;
			_dataFormat = URLLoaderDataFormat.BINARY;
			this.timeout = 20000;
		}
		
		override public function back(...args) : void
		{
			
			//args[0] = String(args[0]).substr(0,String(args[0]).lastIndexOf(">")+1);
			
			var byteArray:ByteArray = ByteArray(args[0]);
			byteArray.uncompress();
			args[0] = byteArray.readMultiByte(byteArray.bytesAvailable,"utf-16");
			//args[0] = byteArray.readUTFBytes(byteArray.bytesAvailable);
			trace("args[0]",args[0],"---");

			if (GameState.DEBUG_STATE == 0)
			{
				try
				{
					backFunction(XML(args[0]),this.id);
				}
				catch (e:Error)
				{
				
					trace("xml Error");
				}
			}
			else
			{
				backFunction(XML(args[0]),this.id);
			}	
		}
		
		
	}
}